/*
 * SharedMem.h
 * 
 * Author: Tarl Hahn
 * Version: 1.0
 *
 * SharedMem is the shared memory area between CPU and the interrupt Controller.
 * This area facilitates communications by holding the io requests from the processes
 * and all the interrupts created by system devices and the timer.
 */

#include<pthread.h>

typedef struct Data
{
	int pid; // process ID
	int did; // device ID
	Data* next; // next
	
	// member functions
	int (*destruct)(struct shared*) // destructs the data pack
} DataPack;

typedef DataPack* DataPackPtr; // DataPack pointer def

DataPackPtr DataPackConstruct(int pid, int did, DataPackPtr next); // constructs a DataPack node for the sharedmem queue.
 
typedef struct shared
{
	DataPackPtr request_list; // array containing device number and process number that owns it.
	DataPackPtr interrupt_list; // array containg the device number and process number that it is returned to
	DataPackPtr head; // head of list
	DataPackPtr tail; // tail of list
	
	int timer_flag; // if 1 timer interrupt, 0 otherwise.
	
	int (*addRequest)(shared*, DataPackPtr, pthread_mutex_t*); // add a request to the queue
	int (*addInterrupt)(shared*, DataPackPtr, pthread_mutex_t*); // add a interrupt to the queue
	DataPackPtr (*getRequest)(shared*, pthread_mutex_t*, int*); // get a request for the queue
	DataPackPtr (*getInterrupt)(shared*, pthread_mutex_t*, int*); // get an interrupt from the queue
	int (*destruct)(shared*); // destruct the shared memory area
	
} SharedMem;

typedef SharedMem* SharedMemPtr; // SharedMem pointer def

SharedMemPtr SharedMemConstruct(void);
 
 
